<?php
	use yii\helpers\Html;
	use yii\widgets\ActiveForm;
	use yii\helpers\ArrayHelper;
	use yii\helpers\Url;
?>
<?php echo $this->render('_centernav');?>
	<div class="you">
	<?php $form = ActiveForm::begin(['action' => ['center/savecenter'],'method'=>'post','fieldConfig' => [
				'template' => '<div class="form-group"><div class="col-md-8 controls"  style="padding-top: 9px">{input}{error}</div></div>'
			],'id'=>'user-form'
]); ?>	

		<?= $form->field($model, 'user_id')->hiddenInput(['value'=>$model->user_id]) ?>
				<div class='form-group'>
				<label class="ptm">昵称:</label>
				<?= $form->field($model, 'user_name')->textInput(['maxlength' => 20,'class'=>'kuang2']) ?><span id='uname'></span></div>
				<div class='form-group'>
				<?php
					if($model->user_phone != ''){
				?>
				<label class="ptm">手机: <a href="javascript:void(0)" id="savephone">修改</a></label>
				<?= $form->field($model, 'user_phone')->textInput(['maxlength' => 20,'class'=>'kuang2','disabled'=>true]) ?>
				<?php }else{?>
				<label class="ptm">手机: <a href="javascript:void(0)" id="bdnewphone">点击绑定</a></label>
				<?php }?>
				</div>
				<div class='form-group'>
				<?php
					if($model->user_email !=""){
				?>
				<label class="ptm">邮箱: <a href="javascript:void(0)" id="saveemail">修改</a></label>
				<?= $form->field($model, 'user_email')->textInput(['maxlength' => 20,'class'=>'kuang2','disabled'=>true]) ?>
				<?php }else{?>
				<label class="ptm">邮箱: <a href="javascript:void(0)" id="bdnewemail">点击绑定</a></label>
				<?php }?>
				</div>
				<div class="form-group">
				<label class="ptm">城市：</label>
				<?= Html::dropDownList('province_id', $model->province_id, ArrayHelper::map($provinces,'id', 'province_id'), ['class' => 'province_id']);?>
				<?= Html::dropDownList('city_id', $model->city_id, ArrayHelper::map($city,'id', 'city_id'), ['class' => 'city_id','id'=>'city_id']);?>
				<?= Html::dropDownList('area_id', $model->area_id, ArrayHelper::map($area,'id', 'area_id'), ['class' => 'area_id','id'=>'area_id']);?>
			</div>
				<div class='form-group'>
				<label class="ptm">QQ:</label>
				<?= $form->field($model, 'user_qq')->textInput(['maxlength' => 20,'class'=>'kuang2']) ?></div>
				<div class='form-group'>
				<label class="ptm">性别:</label>
				<?= $form->field($model, 'user_sex')->radioList(['0'=>'保密','1'=>'男','2'=>'女']) ?></div>
				<div class='form-group'>
				<label class="ptm">标签:</label>
					<div class='biankuang' style='width:370px;height:50px;border:1px solid #000'>
						<div class="biaoqian_k edit_biaoqian_k">
							<ul>
							   
							</ul>
						</div>
					</div>
					<div class="add_biaoqian_r" style='width:370px;height:50px'>
						<ol>
						  <?php foreach($db as $k=>$vo){?>
							<li style="float:left"><p><i name="<?php echo $vo['hobby_id']?>">+</i><b><?php echo $vo['hobby_name'];?></b></p></li>
						  <?php }?>
							
						</ol>
					  
					</div>
				</div>			
			  <div class='form-group'>
			  <label class="ptm">个性签名:</label>
			  <?php
				if($model->user_sign !== ''){
			  ?>
			  <?= $form->field($model, 'user_sign')->textarea(['rows'=>3]) ?>
			  <?php }else{?>
			  <?= $form->field($model, 'user_sign',['inputOptions'=>['placeholder'=>'这位同学很懒，什么也没留下']])->textarea(['rows'=>3]) ?>
			  <?php }?>
			  </div>
			  <?= Html::submitButton('保存', ['class' => 'cun','id'=>'cun']) ?>
			
  
	<?php ActiveForm::end(); ?>
  </div>
    
</div>
<!-- 弹窗 -->
<div class="greybg"></div>
<!-- 修改手机 -->
<div class="popup headscpop" id="headscpop">
    <div class="headscimg">
		手机：<?php echo $model->user_phone;?>
	</div>
	<div class="headscimg">
		验证码：<input type="text" class='phone_code' id='phone' placeholder='请输入验证码' ><input id="zphone" class='code' type="button" value=" 获取手机验证码 "><span id='pcode'></span>
	</div>
	<div class="headscimg">
		<?= Html::Button('下一步',['disabled'=>true,'id'=>'next']) ?>
	</div>
</div>
<!-- 新手机 -->
<div class="popup newphone">
    <div class="headscimg">
		新手机：<input type="text" id='newphone'>
	</div>
	<div class="headscimg">
		验证码：<input type="text" id='newcode' placeholder='请输入验证码' ><input id="hphone" type="button" value=" 获取手机验证码 "><span id='newpcode'></span>
	</div>
	<div class="headscimg">
		<?= Html::Button('修改',['disabled'=>true,'id'=>'save_phone']) ?>
	</div>
</div>
<!-- 绑定新手机 -->
<div class="popup bdphone">
    <div class="headscimg">
		手机：<input type="text" id='bdphone'>
	</div>
	<div class="headscimg">
		验证码：<input type="text" id='bdphonecode' placeholder='请输入验证码' ><input id="bdphones" type="button" value=" 获取手机验证码 "><span id='bdpcode'></span>
	</div>
	<div class="headscimg">
		<?= Html::Button('绑定',['disabled'=>true,'id'=>'bd_phone']) ?>
	</div>
</div>
<!-- 绑定新邮箱 -->
<div class="popup bdemail">
    <div class="headscimg">
		邮箱：<input type="text" id='bdemail'>
	</div>
	<div class="headscimg">
		验证码：<input type="text" id='bdemailcode' placeholder='请输入验证码' ><input id="bdemails" type="button" value=" 获取邮箱验证码 "><span id='bdecode'></span>
	</div>
	<div class="headscimg">
		<?= Html::Button('绑定',['disabled'=>true,'id'=>'bd_email']) ?>
	</div>
</div>
<!-- 修改邮箱 -->
<div class="popup email" >
    <div class="headscimg">
		邮箱：<?php echo $model->user_email?>
	</div>
	<div class="headscimg">
		验证码：<input type="text" class='email_code' id='email' placeholder='请输入验证码' ><input id="zemail" type="button" value=" 获取邮箱验证码 "><span id='pemail'></span>
	</div>
	<div class="headscimg">
		<?= Html::Button('下一步',['disabled'=>true,'id'=>'nextemail']) ?>
	</div>
</div>
<!-- 新邮箱 -->
<div class="popup newemail">
    <div class="headscimg">
		新邮箱：<input type="text" id='newemail'>
	</div>
	<div class="headscimg">
		验证码：<input type="text" id='newemailcode' placeholder='请输入验证码' ><input id="hemail" type="button" value=" 获取邮箱验证码 "><span id='newecode'></span>
	</div>
	<div class="headscimg">
		<?= Html::Button('修改',['disabled'=>true,'id'=>'save_email']) ?>
	</div>
</div>
<!-- 修改成功 -->
<div class="popup success">
    <div class="headscimg">
		<h1><font color='red'>恭喜您操作成功</font></h1>
	</div>
	<div class="headscimg">
		<?= Html::Button('确定',['id'=>'success']) ?>
	</div>
</div>
<script>
/*标签添加*/
        $(".edit_biaoqian_k ul").on("click","li p i",function(){
          var oneBq=$(this).parents("li")
		  $(".edit_biaoqian_k ul input").remove();
          oneBq.hide();
          var addText=$(this).siblings("b").text();
          $(".add_biaoqian_r ol").append("<li style='float:left'><p><i>+</i><b>"+addText+"</b></p></li>")
          $(".label").attr('class','labels')
        })
        $(".add_biaoqian_r ol").on("click","li p i",function(){
          var oneBq=$(this).parents("li")
          oneBq.hide();
          var addText=$(this).siblings("b").text();
          var hobby_id = $(this).attr('name');
          $(".edit_biaoqian_k ul").append("<li style='float:left'><p><b class='label' style='color:#000'>"+addText+"</b><i>×</i></p></li><input type='hidden' name='User[hobby_id][]' value='"+hobby_id+"'/>")
        })
		$('#user-user_name').blur(function(){
			var user_name = $(this).val();
			if(user_name==""){
				$('#uname').html('昵称不能为空');die;
			}
			if(user_name == "<?php echo $model->user_name;?>"){
				$('#uname').html('');
				die;
			}
			$.ajax({
			   type: "POST",
			   url: "<?= Url::to(['index/unique'])?>",
			   data: "user_name="+user_name,
			   success: function(msg){
					if(msg == 1){
						$('#uname').html('当前昵称已被使用');
					}else{
						$('#uname').html('');
					}
			   }
		});
		}
	)
//弹窗    
function popup(){
	$("body").css({height:"100%"});
	$(".greybg").fadeIn(100);
};

function closepop(){
	window.goUrl = '';
	$("body").removeAttr("style");
	$(".greybg").fadeOut(100);
};
$(function(){
			$("#savephone").click(function(){
				popup();
				$(".headscpop").fadeIn(100);
			})
			$("#saveemail").click(function(){
				popup();
				$(".email").fadeIn(100);
			})
			$("#bdnewphone").click(function(){
				popup();
				$(".bdphone").fadeIn(100);
			})
				$("#bdnewemail").click(function(){
				popup();
				$(".bdemail").fadeIn(100);
			})
			$(".guanbidiv").click(function(){
				closepop();
				$(this).parents(".popup").fadeOut(100);
			});
			$(".popuptit .close").click(function(){
				closepop();
				$(this).parents(".popup").fadeOut(100);
			});
		}
	)
$("#next").click(function(){
	$(".headscpop").css('display','none');
	$(".newphone").css('display','block');
})
$("#nextemail").click(function(){
	$(".email").css('display','none');
	$(".newemail").css('display','block');
})
$(".code").click(function(){
		var phone = "<?php echo $model->user_phone?>";
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/codes'])?>",
		   data: "phone="+phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTime();
				alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				alert('发送失败,请重新获取验证码')		
			 }
		   }
		});
	})
//获取邮箱验证码
$("#zemail").click(function(){
var phone = "<?php echo $model->user_email;?>";
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/codes'])?>",
		   data: "phone="+phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTimess();
				alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				alert('发送失败,请重新获取验证码')		
			 }
		   }
		});
})
$("#hemail").click(function(){
var phone = $("#newemail").val();
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/codes'])?>",
		   data: "phone="+phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTimess();
				alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				alert('发送失败,请重新获取验证码')		
			 }
		   }
		});
})
$("#hphone").click(function(){

		var phone = $('#newphone').val()
		$.ajax({   
		type: "POST",
		   url: "<?= Url::to(['center/codes'])?>",
		   data: "phone="+phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTimes();
				alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				alert('发送失败,请重新获取验证码')		
			 }
		   }
		});
	})


	var iTime = 59;
	var Account;
	function RemainTime(){
		document.getElementById('zphone').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒后再次获取";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取验证码';
				iTime = 59;
				document.getElementById('zphone').disabled = false;
			}else{
				Account = setTimeout("RemainTime()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('zphone').value = sTime;
	}
	function RemainTimes(){
		document.getElementById('hphone').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒后再次获取";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取验证码';
				iTime = 59;
				document.getElementById('hphone').disabled = false;
			}else{
				Account = setTimeout("RemainTimes()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('hphone').value = sTime;
	}
	function RemainTimess(){
		document.getElementById('zemail').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒后再次获取";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取验证码';
				iTime = 59;
				document.getElementById('zemail').disabled = false;
			}else{
				Account = setTimeout("RemainTimess()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('zemail').value = sTime;
	}
//验证验证码
$(".phone_code").blur(function(){
	var phone = "<?php echo $model->user_phone?>";
	var code = $('#phone').val()
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('next').disabled = true;
				$('#pcode').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('next').disabled = false;
				 $('#pcode').html('');
			 }else{
				document.getElementById('next').disabled = true;
				$('#pcode').html('验证码错误');
			 }
		   }
		});
})
$("#email").blur(function(){
	var phone = "<?php echo $model->user_email;?>";
	var code = $(this).val()
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('nextemail').disabled = true;
				$('#pemail').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('nextemail').disabled = false;
				 $('#pemail').html('');
			 }else{
				document.getElementById('nextemail').disabled = true;
				$('#pemail').html('验证码错误');
			 }
		   }
		});
})
//验证新手机验证码
$("#newcode").blur(function(){
	var code = $(this).val();
	var phone = $('#newphone').val()
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('save_phone').disabled = true;
				$('#newpcode').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('save_phone').disabled = false;
				 $('#newpcode').html('');
			 }else{
				document.getElementById('save_phone').disabled = true;
				$('#newpcode').html('验证码错误');
			 }
		   }
		});
})
//验证新邮箱验证码
$("#newemailcode").blur(function(){
	var code = $(this).val();
	var phone = $('#newemail').val()
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('save_email').disabled = true;
				$('#newecode').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('save_email').disabled = false;
				 $('#newecode').html('');
			 }else{
				document.getElementById('save_email').disabled = true;
				$('#newecode').html('验证码错误');
			 }
		   }
		});
})
//修改手机
$("#save_phone").click(function(){
	var phone = "<?php echo $model->user_phone?>";
	var new_phone = $('#newphone').val();
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/savephone'])?>",
		   data: "phone="+phone+"&new_phone="+new_phone,
		   success: function(msg){
			 if(msg == 1){
				$(".newphone").css('display','none');
				$(".success").css('display','block');
			 }else{
				alert('修改失败');
			 }
		   }
		});
})
//修改邮箱
$("#save_email").click(function(){
	var email = "<?php echo $model->user_email;?>";
	var new_email = $('#newemail').val();
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/saveemail'])?>",
		   data: "email="+email+"&new_email="+new_email,
		   success: function(msg){
			 if(msg == 1){
				$(".newemail").css('display','none');
				$(".success").css('display','block');
			 }else{
				alert('修改失败');
			 }
		   }
		});
})
//成功后跳转
$("#success").click(function(){
	location.href="<?= Url::to(['center/index'])?>";
})
//绑定新手机
//1.获取新手机的验证码
$("#bdphones").click(function(){
var phone = $("#bdphone").val();
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/codes'])?>",
		   data: "phone="+phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTimesss();
				alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				alert('发送失败,请重新获取验证码')		
			 }
		   }
		});
})
function RemainTimesss(){
		document.getElementById('bdphones').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒后再次获取";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取验证码';
				iTime = 59;
				document.getElementById('bdphones').disabled = false;
			}else{
				Account = setTimeout("RemainTimesss()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('bdphones').value = sTime;
	}
//2.检验验证码
$("#bdphonecode").blur(function(){
	var phone = $("#bdphone").val();
	var code = $(this).val()
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('bd_phone').disabled = true;
				$('#bdpcode').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('bd_phone').disabled = false;
				 $('#bdpcode').html('');
			 }else{
				document.getElementById('bd_phone').disabled = true;
				$('#bdpcode').html('验证码错误');
			 }
		   }
		});
})
//3.绑定
$("#bd_phone").click(function(){
	var user_id = "<?php echo $model->user_id;?>";
	var phone = $("#bdphone").val();
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/bdphone'])?>",
		   data: "phone="+phone+"&user_id="+user_id,
		   success: function(msg){
			 if(msg == 1){
				$(".bdphone").css('display','none');
				$(".success").css('display','block');
			 }else{
				alert('修改失败');
			 }
		   }
		});
})
//绑定新邮箱
//1.获取新手机的验证码
$("#bdemails").click(function(){
var phone = $("#bdemail").val();
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/codes'])?>",
		   data: "phone="+phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTimessss();
				alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				alert('发送失败,请重新获取验证码')		
			 }
		   }
		});
})
function RemainTimessss(){
		document.getElementById('bdemails').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒后再次获取";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取验证码';
				iTime = 59;
				document.getElementById('bdemails').disabled = false;
			}else{
				Account = setTimeout("RemainTimessss()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('bdemails').value = sTime;
	}
//2.检验验证码
$("#bdemailcode").blur(function(){
	var phone = $("#bdemail").val();
	var code = $(this).val()
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('bd_email').disabled = true;
				$('#bdecode').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('bd_email').disabled = false;
				 $('#bdecode').html('');
			 }else{
				document.getElementById('bd_email').disabled = true;
				$('#bdecode').html('验证码错误');
			 }
		   }
		});
})
//3.绑定
$("#bd_email").click(function(){
	var user_id = "<?php echo $model->user_id;?>";
	var email = $("#bdemail").val();
	$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/bdemail'])?>",
		   data: "email="+email+"&user_id="+user_id,
		   success: function(msg){
			 if(msg == 1){
				$(".bdemail").css('display','none');
				$(".success").css('display','block');
			 }else{
				alert('修改失败');
			 }
		   }
		});
})
//城市
$(document).on('change', '.province_id', function(){
        var id=$(this).val();
		var objs = $(this);
		
        //var next=$(this).parent().next();
        //var nexttwo=next.next();
        //alert(next);
        $.ajax({
            type: "POST",
            url:"<?= Url::to(['center/sel'])?>",
            data: "id="+id,
            dataType:"json",
            success: function(obj){
                var str="";
                var i=0;
                for(i;i<obj.length;i++){
                    str+="<option value="+obj[i]['region_id']+">"+obj[i]['region_name'];
                }
                objs.next().html(str);
				objs.next().next().html("<option value=''>请选择...");
            }
        });
    })
//城市
$(document).on('click', '.city_id', function(){
        var id=$(this).val();		
        var next=$(this).next();
        //var nexttwo=next.next();
        //alert(next);
        $.ajax({
            type: "POST",
            url:"<?= Url::to(['center/sel'])?>",
            data: "id="+id,
            dataType:"json",
            success: function(obj){
                var str="";
                var i=0;
                for(i;i<obj.length;i++){
                    str+="<option value="+obj[i]['region_id']+" class='city_id'>"+obj[i]['region_name'];
                }
                next.html(str);
                //obj.next().nextAll().html("<option>哈哈哈哈</option>");
                //nexttwo.html("<option value=0>请选择...");
            }
        });
    })
</script>